package main

import (
	"fmt"
	"gitee.com/DonHz/cloud-file-storage/service/upload/config"
	"gitee.com/DonHz/cloud-file-storage/service/upload/proto"
	"gitee.com/DonHz/cloud-file-storage/service/upload/route"
	"gitee.com/DonHz/cloud-file-storage/service/upload/rpc"
	"github.com/go-micro/plugins/v4/registry/consul"
	"go-micro.dev/v4"
	"go-micro.dev/v4/registry"
)

func main() {
	go startAPIService()
	startRPCService()
}

func startAPIService() {
	router := route.Router()
	router.Run(config.UploadServiceAddr)
}

func startRPCService() {
	registry := consul.NewRegistry(registry.Addrs("127.0.0.1:8500"))
	service := micro.NewService(
		micro.Name("go.micro.service.upload"), // 服务名称
		micro.Handle(new(proto.UploadServiceHandler)),
		micro.Registry(registry),
	)
	service.Init()

	proto.RegisterUploadServiceHandler(service.Server(), new(rpc.UploadService))
	if err := service.Run(); err != nil {
		fmt.Println(err)
		return
	}
}
